//
// Created by 李传智 on 2018/4/14.
//

#include "IPlayerBuilder.h"
#include "IDemux.h"
#include "IDecode.h"
#include "IResample.h"
#include "IAudioPlay.h"
#include "IVideoView.h"
#include "IPlayer.h"

IPlayer *IPlayerBuilder::buildPlayer(unsigned char index) {

    IPlayer *player = createPlayer(index);

    player->demux = createDemux();

    player->audioDecode = createDecode();
    player->demux->addObserver(player->audioDecode);

    player->videoDecode = createDecode();
    player->demux->addObserver(player->videoDecode);

    player->videoView = createVideoView();
    player->videoDecode->addObserver(player->videoView);

    player->resample = createResample();
    player->audioDecode->addObserver(player->resample);

    player->audioPlay = createAudioPlay();
    player->resample->addObserver(player->audioPlay);

    player->recorder = createRecorder();
    player->demux->addObserver(player->recorder);

    return player;
}